#!/bin/bash
nginx_home=/opt/module/nginx
log_home=/opt/module/gmall1026
app=gmall-logger-0.0.1-SNAPSHOT.jar


case $1 in
"start")
# 启动 nginx



if [[ -z "`ps -ef | awk '/nginx/ && !/awk/{ print \$n}'`" ]]; then
    echo "在hadoop162上启动 nginx"
    $nginx_home/sbin/nginx
else
    echo "在hadoop162上nginx已经启动, 不用重新启动"
fi

for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 上启动日志服务器"
    ssh $host "nohup java -jar $log_home/$app >/dev/null 2>&1 & "
done



# 分别在三个节点启动日志服务器
   ;;
"stop")
echo "在hadoop162上停止 nginx"
$nginx_home/sbin/nginx -s stop
for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 上停止日志服务器"
    ssh $host "jps | awk '/gmall/ {print \$1}' | xargs kill -9"
done

   ;;
*)
    echo "你启动的姿势不对"
    echo " log.sh start 启动日志采集集群"
    echo " log.sh stop  停止日志采集集群"
   ;;
esac


